﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;


namespace ClipboardTranslator
{
    public class AutoRun
    {
        const string RUN_LOCATION = @"Software\Microsoft\Windows\CurrentVersion\Run";

        const string key_name = "ClipboardTranslator";

        public static bool Enabled
        {
            get
            {
                RegistryKey key = Registry.CurrentUser.OpenSubKey(RUN_LOCATION);
                if (key == null)
                    return false;

                string value = (string)key.GetValue(key_name);
                if (value == null)
                    return false;

                return (value == Program.ApplicationPath);
            }

            set
            {
                if (value)
                {
                    RegistryKey key = Registry.CurrentUser.CreateSubKey(RUN_LOCATION);
                    key.SetValue(key_name, Program.ApplicationPath);
                }
                else
                {
                    RegistryKey key = Registry.CurrentUser.CreateSubKey(RUN_LOCATION);
                    key.DeleteValue(key_name);
                }
            }
        }
    }
}
